//
//  YRecommendeBookListDetailHeaderView.m
//  Reader
//
//  Created by yuemei on 2019/5/22.
//  Copyright © 2019 SF. All rights reserved.
//

#import "YRecommendeBookListDetailHeaderView.h"
#import "YRecommendBookListDetailModel.h"

@interface YRecommendeBookListDetailHeaderView()
@property (nonatomic, strong) UIImageView *headerImg;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *nickLab;
@property (nonatomic, strong) UILabel *hintLab;
@end

@implementation YRecommendeBookListDetailHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}



-(void)setupUI{
    [self.contentView setBackgroundColor:HexColor(0xf7f7f7, 1)];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.headerImg];
    [self.contentView addSubview:self.nickLab];
    [self.contentView addSubview:self.hintLab];
    
    [_titleLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).inset(15);
        make.left.equalTo(self.contentView).inset(18);
    }];
    [_headerImg makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLab.mas_bottom).inset(15);
        make.left.equalTo(_titleLab);
        make.size.equalTo(CGSizeMake(18, 18));
    }];
    [_nickLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImg.mas_right).offset(8);
        make.centerY.equalTo(_headerImg);
    }];
    [_hintLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_headerImg.mas_bottom).offset(15);
        make.left.equalTo(_headerImg);
        make.right.equalTo(self.contentView).inset(18);
    }];
    
}
-(void)setModel:(YRecommendBookListDetailModel *)model{
    _model = model;
    [self.headerImg sd_setImageWithURL:[YURLManager getURLWith:YAPITypeAuthorAvatar parameter:model.author.avatar] placeholderImage:kImageDefaltAuthorAvatar];
    self.titleLab.text = model.title;
    self.nickLab.text = model.author.nickname;
    self.hintLab.text  =  model.desc;
}

-(UIImageView *)headerImg{
    if (!_headerImg) {
        _headerImg = [UIImageView new];
        _headerImg.layer.cornerRadius = 9;
        _headerImg.layer.masksToBounds = YES;
    }
    return _headerImg;
}

-(UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = [UIFont systemFontOfSize:20 weight:UIFontWeightMedium];
        _titleLab.textColor = HexColor(0x333333,1);
    }
    return _titleLab;
}

-(UILabel *)nickLab{
    if (!_nickLab) {
        _nickLab = [UILabel new];
        _nickLab.font = [UIFont systemFontOfSize:11];
        _nickLab.textColor = HexColor(0x333333,1);
    }
    return _nickLab;
}

-(UILabel *)hintLab{
    if (!_hintLab) {
        _hintLab = [UILabel new];
        _hintLab.font = [UIFont systemFontOfSize:12];
        _hintLab.textColor = HexColor(0xa3a3a3,1);
        _hintLab.numberOfLines = 0;
    }
    return _hintLab;
}


@end

